﻿Public Class FormIntoRecord
    Dim objjl_ck As New clsJLck
    Dim txt As TextBox
    Private Sub FormIntoRecord_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim startDate As String = Date.Now.AddDays(-1).ToShortDateString()
        txtStartDate.Text = startDate
        Dim endDate As String = Date.Now.ToShortDateString()
        txtEndDate.Text = endDate
        setDgvData()
    End Sub
    Private Sub btnSearce_Click(sender As Object, e As EventArgs) Handles btnSearce.Click
        setDgvData()
    End Sub

    Private Sub setDgvData()
        If String.IsNullOrEmpty(txtStartDate.Text.Trim()) = False And String.IsNullOrEmpty(txtEndDate.Text.Trim()) = False Then
            Dim dtJl As DataTable = objjl_ck.getJlCkInList(txtStartDate.Text.Trim() + " 00:00:00.000",
                                                              txtEndDate.Text.Trim() + " 23:59:59.999",
                                                              txtCode.Text.Trim())
            dgv.AutoGenerateColumns = False
            dgv.DataSource = dtJl
        Else
            MsgBox("请输入开始时间和结束时间", vbYes, "提示")
        End If
    End Sub

    Private Sub dgv_SelectionChanged(sender As Object, e As EventArgs) Handles dgv.SelectionChanged
        Dim dtDetails As New DataTable
        If dgv.SelectedRows.Count > 0 Then
            dtDetails = objjl_ck.getJlCkInDetailsList(dgv.SelectedRows(0).Cells("ck_in_code").Value.ToString())
            dtDetails.Columns.Add("validity_name")
            If dtDetails.Rows.Count > 0 Then
                For Each row As DataRow In dtDetails.Rows
                    If row("validity") = "0" Then
                        row("validity_name") = "无效"
                    Else
                        row("validity_name") = "有效"
                    End If
                Next
            End If
        End If
        dgv1.AutoGenerateColumns = False
        dgv1.DataSource = dtDetails
    End Sub

    Private Sub btnValidity_Click(sender As Object, e As EventArgs)
        If dgv1.SelectedRows.Count > 0 Then
            If dgv1.SelectedRows(0).Cells("Col_validity").Value.ToString().Equals("1") Then
                Dim rtn As Integer = objjl_ck.updateInDetailsVlidity("0",
                                                                     dgv1.SelectedRows(0).Cells("Col_sys_id").Value.ToString(),
                                                                     dgv1.SelectedRows(0).Cells("ColBatchNo").Value.ToString(),
                                                                     dgv1.SelectedRows(0).Cells("Col_mst_value").Value.ToString(),
                                                                     dgv1.SelectedRows(0).Cells("Col_into_weight").Value.ToString())
                If rtn <> -2 Then
                    MsgBox("作废成功")
                    setDgvData()
                    CType(Owner, FormMain).initData()
                Else
                    MsgBox("作废失败")
                End If
            Else
                MsgBox("该入库记录已作废")
            End If
        End If
    End Sub


    Private Sub txt_MouseClick(sender As Object, e As MouseEventArgs) Handles txtStartDate.MouseClick, txtEndDate.MouseClick
        txt = CType(sender, TextBox)
        DateNavigator1.Left = txt.Left
        DateNavigator1.Top = txt.Location.Y + txt.Height
        DateNavigator1.Visible = True
    End Sub

    Private Sub DateNavigator1_DateTimeChanged(sender As Object, e As EventArgs) Handles DateNavigator1.DateTimeChanged
        txt.Text = DateNavigator1.DateTime.ToShortDateString()
        DateNavigator1.Visible = False
    End Sub

End Class